import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/pages/teacher/assessmentBooks.dart';
import 'package:ichinesereader/pages/teacher/assessmentManagement.dart';
import 'package:ichinesereader/pages/teacher/assessmentRecords.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerTeacher.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import '../../themes/appTheme.dart';
import '../../themes/pageStyles.dart';
import '../../widgets/sidebars/teacherSidebar.dart';

late TabController teacherAssessmentTabController;

class AssessmentsTeacherPage extends StatefulWidget {
  AssessmentsTeacherPage({Key? key}) : super(key: key);
  static const String routeName = '/teacher/assessments';

  @override
  State<AssessmentsTeacherPage> createState() => AssessmentsTeacherPageState();
}

class AssessmentsTeacherPageState extends State<AssessmentsTeacherPage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    teacherAssessmentTabController = TabController(vsync: this, length: 3);
    super.initState();
  }

  @override
  void dispose() {
    //Get.delete<ReportsController>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build teacher assessments page');
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;
    int _selectedSidebarItem = RoutePages.teacherPageItems
        .indexWhere((page) => page.route == Get.currentRoute);
    final PageStyles _pageStyles = PageStyles();

    return DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: isSmallScreen ? CustomAppBar(title: 'Assessments'.tr) : null,
          drawer: isSmallScreen ? TeacherAppDrawer() : null,
          //floatingActionButton: FloatingActionButtonsTeacherSwitchClass(),
          body: Container(
            decoration: _pageStyles.pageBoxDecoration(),
            child: Row(
              children: [
                Visibility(
                    visible: !isSmallScreen,
                    child: TeacherSidebarX(
                      selectedIndex: _selectedSidebarItem,
                      isBigScreen: isBigScreen,
                    )),
                Expanded(
                  flex: 9,
                  child: Container(
                    margin: _pageStyles.mainContainerPageEdgeInsets(),
                    child: Column(
                      children: [
                        Stack(
                          alignment: Alignment.center,
                          children: [
                            Container(
                              padding: EdgeInsets.all(30.0),
                              decoration: BoxDecoration(
                                color: Get.isDarkMode
                                    ? AppTheme.colors.darkTheme2
                                    : Colors.black.withOpacity(0.1),
                                borderRadius: BorderRadius.circular(3.0),
                              ),
                            ),
                            _pageStyles.buildTabBarWithContoller(
                                ['Management', 'Assessment Books', 'Records'],
                                teacherAssessmentTabController),
                          ],
                        ),
                        Expanded(
                          flex: 9,
                          child: Container(
                            child: TabBarView(
                              controller: teacherAssessmentTabController,
                              children: [
                                AssessmentsManagement(),
                                AssessmentBooksTeacherPage(),
                                TeacherAssessmentRecords()
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ));
  }
}
